package updateDatabases;

import java.util.Date;
import java.util.Timer;
import java.util.TimerTask;

/**
 * the timer class that will auto start every morning at 1am. it will call UpdateBotFinal which will
 * update the database.
 * 
 * @author Yahweh Yago
 * 
 */
public class MyTimer extends TimerTask {
  private final static long ONCE_PER_DAY = 1000 * 60 * 60 * 24;

  private final static int ONE_HOUR = 1;
  private final static int ZERO_MINUTES = 0;

  public static void main(String args[]) {
    Date timeee = new Date();
    System.out.println(timeee);
    startTask();

  }

  @Override
  public void run() {
    long currentTime = System.currentTimeMillis();
    long stopTime = currentTime + 120000;
    while (stopTime != System.currentTimeMillis()) {
      // call the UpdateBotFinal file
      UpdateBotFinal.updateGAMERS();
      System.out.println("Start Job" + stopTime);
      System.out.println("End Job" + System.currentTimeMillis());
    }
  }

  /*
   * Time when the update will execute.
   */
  private static Date update1AM() {

    Date date2am = new java.util.Date();
    date2am.setHours(ONE_HOUR);
    date2am.setMinutes(ZERO_MINUTES);

    return date2am;
  }

  /*
   * Starts the task
   */
  public static void startTask() {
    MyTimer task = new MyTimer();
    Timer timer = new Timer();
    timer.schedule(task, update1AM(), 1000 * 60 * 60 * 24);// for your case u need to give
                                                           // 1000*60*60*24
  }
}